//
//  LGCarePlanManageCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/13.
//  管理照护计划

#import "LGCarePlanManageCell.h"

@interface LGCarePlanManageCell()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIButton *addButton;
/**   */
@property (nonatomic , strong)UIButton *sureButton;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UILabel *serviceTitle;
/**   */
@property (nonatomic , strong)UILabel *serviceLabel;
/**   */
@property (nonatomic , strong)UILabel *planTitle;
/**   */
@property (nonatomic , strong)UILabel *planLabel;
/**   */
@property (nonatomic , strong)UIButton *historyBtn;
/**   */
@property (nonatomic , strong)UIButton *patientBtn;
/**   */
@property (nonatomic , strong)UIButton *planButton;

@end

@implementation LGCarePlanManageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    //性别、年龄
    NSString *gender = LGNSString(dataDic[@"sex"]);
    NSString *age = LGNSString(dataDic[@"age"]);
    if(gender.length>0 && age.length >0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@  %@岁",gender,age];
    }else if (gender.length > 0 && age.length == 0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@",gender];
    }else if (gender.length == 0 && age.length>0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@岁",age];
    }else{
        self.ageLabel.text = @"";
    }
    NSString *vipDate = LGNSString(dataDic[@"vip_enddate"]);
    self.serviceLabel.text = (vipDate.length>0)?[NSString stringWithFormat:@"有效期至 %@",vipDate]:@"";
    NSString *planDate = LGNSString(dataDic[@"careplan_updatedate"]);
    NSString *planColor = (planDate.length>0)?@"#333333":@"#999999";
    self.planLabel.text = (planDate.length>0)?[NSString stringWithFormat:@"%@ 更新",planDate]:@"暂无";
    self.planLabel.textColor = [UIColor colorWithString:planColor];
    NSArray *statusArray = dataDic[@"status"];
    self.sureButton.hidden = [statusArray containsObject:@"2"]?NO:YES;
    self.addButton.hidden = [statusArray containsObject:@"1"]?NO:YES;
    CGFloat rightMargin = [statusArray containsObject:@"2"]?-viewPix(77):-viewPix(12);
    [self.addButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(rightMargin);
    }];
}

-(void)patientBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(checkPatientDetail:)]){
        [self.delegate checkPatientDetail:self.dataDic];
    }
}

-(void)planBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(checkCarePlan:diseaseCode:)]){
        [self.delegate checkCarePlan:LGNSString(self.dataDic[@"patient_id"]) diseaseCode:LGNSString(self.dataDic[@"disease_code"]) levelid:LGNSString(self.dataDic[@"level_id"])];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.addButton];
    [self.baseView addSubview:self.sureButton];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.serviceTitle];
    [self.baseView addSubview:self.serviceLabel];
    [self.baseView addSubview:self.planTitle];
    [self.baseView addSubview:self.planLabel];
    [self.baseView addSubview:self.historyBtn];
    [self.baseView addSubview:self.patientBtn];
    [self.baseView addSubview:self.planButton];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(12));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(77));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(60)));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.width.height.equalTo(self.addButton);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(42));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.height.equalTo(@(0.5));
    }];
    [self.serviceTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.nameLabel);
    }];
    [self.serviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.serviceTitle.mas_right).offset(viewPix(12));
        make.centerY.equalTo(self.serviceTitle);
    }];
    [self.planTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.serviceTitle.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.serviceTitle);
    }];
    [self.planLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.planTitle.mas_right).offset(viewPix(12));
        make.centerY.equalTo(self.planTitle);
    }];
    [self.historyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.serviceTitle);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.patientBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.planTitle.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.nameLabel);
        make.width.equalTo(@((Screen_W-viewPix(60))/2.0));
        make.height.equalTo(@(viewPix(30)));
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
    }];
    [self.planButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.patientBtn.mas_right).offset(viewPix(8));
        make.centerY.width.height.equalTo(self.patientBtn);
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIButton *)addButton{
    if(!_addButton){
        _addButton = [UIButton buttonWithTitle:@" 待新增" titleFont:LGFontWeight(13, UIFontWeightMedium) textColor:@"#FDB33D" imageName:@"照护计划-待新增"];
        _addButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    }
    return _addButton;
}

-(UIButton *)sureButton{
    if(!_sureButton){
        _sureButton = [UIButton buttonWithTitle:@" 待确认" titleFont:LGFontWeight(13, UIFontWeightMedium) textColor:@"#2FBC93" imageName:@"照护计划-待确认"];
        _sureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    }
    return _sureButton;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UILabel *)serviceTitle{
    if(!_serviceTitle){
        _serviceTitle = [UILabel lableWithText:@"服务包" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _serviceTitle;
}

-(UILabel *)serviceLabel{
    if(!_serviceLabel){
        _serviceLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _serviceLabel;
}

-(UILabel *)planTitle{
    if(!_planTitle){
        _planTitle = [UILabel lableWithText:@"照护计划" colorString:@"#666666" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _planTitle;
}

-(UILabel *)planLabel{
    if(!_planLabel){
        _planLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _planLabel;
}

-(UIButton *)historyBtn{
    if(!_historyBtn){
        _historyBtn = [UIButton buttonWithTitle:@"签约历史" titleFont:LGFont(14) textColor:@"#4C87FD" imageName:@"blueTip12"];
        _historyBtn.bounds = CGRectMake(0, 0, viewPix(70), viewPix(20));
        _historyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_historyBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
        _historyBtn.userInteractionEnabled = NO;
    }
    return _historyBtn;
}

-(UIButton *)patientBtn{
    if(!_patientBtn){
        _patientBtn = [UIButton buttonWithTitle:@"患者档案" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#4C87FD" imageName:@""];
        _patientBtn.layer.borderColor = [UIColor colorWithString:@"#4C87FD"].CGColor;
        _patientBtn.layer.borderWidth = 1;
        _patientBtn.cornerRidus = viewPix(15);
        [_patientBtn addTarget:self action:@selector(patientBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _patientBtn;
}

-(UIButton *)planButton{
    if(!_planButton){
        _planButton = [UIButton buttonWithTitle:@"照护计划" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#FFFFFF" imageName:@""];
        _planButton.backgroundColor = [UIColor colorWithString:@"#3291FF"];
        _planButton.cornerRidus = viewPix(15);
        [_planButton addTarget:self action:@selector(planBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _planButton;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
